home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / dev / lang / Python152_Src.lha / Python152_Source / Amiga_Misc / Docs / Dos_module < prev    next >
Text File  |  1998-11-12  |  11KB  |  322 lines

  1.  
  2. ***************************************************************************
  3.  
  4.                         PYTHON dos.library SUPPORT
  5.  
  6.                           Dos and Doslib modules
  7.     
  8.                    by Irmen de Jong - irmen@bigfoot.com
  9.  
  10.                           Last update: 27-Sep-98
  11.  
  12.                                BETA VERSION
  13.  
  14. ***************************************************************************
  15.  
  16. As  this  document  describes  the  BETA VERSION of the dos.library support
  17. there  might come changes to what is described below.  This depends on bugs
  18. found  and  suggestions received.  So please:  test the dos.library support
  19. and let me hear any problems/bugs/suggestions (irmen@bigfoot.com).
  20.  
  21. Check  the  entries  marked  ***  NEW *** for what's new since the previous
  22. version.
  23.  
  24. ***************************************************************************
  25.  
  26.                               MODULE: Doslib
  27.  
  28.                             FILE: N/A (builtin)
  29.  
  30. ***************************************************************************
  31.  
  32. This module provides the low-level dos.library functionality.
  33.  
  34. IMPORTANT:   It  is  DISCOURAGED  to  use this module directly, use the Dos
  35. module  instead  (see  below).  The Dos module imports everything from this
  36. module  so  you can access everything through the Dos module instead.  This
  37. is  much  like  how the string module uses the builtin strop module:  don't
  38. use the builtin lowlevel module directly!
  39.  
  40. This module defines the following exception:
  41.  
  42.   error        - The exception that will be raised when an
  43.           error occurs related to dos.library. ('Doslib.error')
  44.  
  45.  
  46. +--------------------------------------+
  47. |                                      |
  48. |          DEFINED FUNCTIONS           |
  49. |                                      |
  50. +--------------------------------------+
  51.  
  52. ReadArgs
  53.     INTENTIONALLY UNDOCUMENTED. USE ArgParser CLASS FROM `Dos' MODULE!
  54.  
  55. WaitSignal(what)
  56.     Generic Wait() function to wait for signals, modeled after the `select'
  57.     function. Usage: (sigs,objlist) = WaitSignal(what)
  58.        what = integer, object, or a list of ints and/or objects.
  59.        Integers are sigmask values. Objects must have a 'signal' attribute
  60.        which is their sigmask value. When a list is given the sigmasks of
  61.        the items are or-ed together (max 32 items).
  62.     RESULT: sigs = the signals that occured (sigmask).
  63.             objlist = a list of the objects whose signal occured.
  64.     NOTE: any signals that were detected are cleared when WaitSignal()
  65.     returns. Signals that were not waited upon are not cleared.
  66.  
  67. CheckSignal(what)
  68.     Like WaitSignal (see above) but DOESN'T WAIT, merely checks if certain
  69.     signals are set. NOTE: any signals that were detected are cleared when
  70.     CheckSignal() returns. Signals that were not checked upon are not
  71.     cleared.
  72.  
  73. CompareDates(d1,d2)
  74.     Compares the two 3-tuple DateStamps d1 and d2 and returns:
  75.     <0 if d1 is later than d2
  76.      0 if d1 = d2
  77.     >0 if d1 is before d2
  78.  
  79. DateStamp()
  80.     Returns 3-tuple AmigaDOS DateStamp (current date & time).
  81.  
  82. DateToStr(date,format=FORMAT_DOS,flags=0)
  83.     Convert 3-tuple DateStamp to readable 3-tuple date string.
  84.     date = DateStamp
  85.     format and flags are optional.
  86.     format = how to format the string (see Dos.py module for definitions)
  87.     flags = flags (see Dos.py module for definitions)
  88.     
  89. StrToDate(dstr [,timestring, format = FORMAT_DOS, flags = 0] )
  90.     Convert AmigaDOS date string to AmigaDOS DateStamp.
  91.     dstr = date string (like '27-Aug-96')
  92.     timestring = time string (optional, like '16:12:00')
  93.     format = string format (optional, see Dos.py module for definitions)
  94.     flags = flags (see Dos.py module for definitions)
  95.     
  96. Fault(err [,header])
  97.     Returns DOS error message string.
  98.     err = Dos error code
  99.     header = error header string (optional, defaults to None which means
  100.              no header)
  101.  
  102. GetProgramDir()            *** NEW ***
  103.     Returns the directory the program (the python interpreter) was launched
  104.     from. Will usually be the directory where your Python: assign points to.
  105.     Returns empy string when Python is launched as resident program (note
  106.     that at the time of writing this is not possible).
  107.  
  108. GetProgramName()        *** NEW ***
  109.     Returns the full CLI name of the program (the python interpreter).
  110.     Will fail if Python is launched from the Workbench.
  111.     
  112. Inhibit(drive, switch=1)    *** NEW ***
  113.     Inhibits the specified drive (like 'HD0:') from access ("XXX: BUSY"
  114.     appears on the Workbench). Use '1' as switch to inhibit, '0' to remove
  115.     the restrictions (defaults to 1 when omitted).
  116.  
  117. IoErr()
  118.     Returns last DOS IoErr() error value.
  119.  
  120. SetIoErr(err)
  121.     Set new DOS IoErr() error value, and returns previous value.
  122.  
  123. IsFileSystem(path)
  124.     Checks if path is a filesystem device.
  125.  
  126. Relabel(oldvolname,newvolname)
  127.     Relabel a disk.
  128.     oldvolname = old volume name (including :)
  129.     newvolname = new volume name (without :)
  130.     
  131. SetProtection(file,protbits)
  132.     Set DOS file protection bits.
  133.     file = filename
  134.     protbits = protection bits for this file (see Dos.py module for
  135.                definitions)
  136.  
  137. SetComment(file,comment)
  138.     Set DOS file comment string.
  139.     file = filename
  140.     comment = file comment string for this file
  141.  
  142. SetFileDate(file, datestamp)        *** NEW ***
  143.     Sets the file's datestamp to the given datestamp.
  144.  
  145. SetOwner(file, uid, gid)        *** NEW ***
  146.     Sets the file's owner UID and owner GID.
  147.     Note that this call needs Kickstart 3.0 or higher.
  148.     
  149. Examine(file)
  150.     Examine a file or directory. Returns the following 10-tuple:
  151.     (filename,size,type,protection,diskkey,#blocks,
  152.      3-tuple DateStamp, comment, owner UID, owner GID )
  153.     The indexes of these members are defined in the Dos module;
  154.     fib_FileName, fib_Size,....  See Dos.py.
  155.  
  156. Info(drivename)                *** NEW ***
  157.     Returns information on the specified drive, as the following 7-tuple:
  158.     (NumSoftErrors, UnitNumber, DiskState, NumBlocks, NumBlocksUsed,
  159.      BytesPerBlock, DiskType, InUse).   (all 7 are integers).
  160.     The indexes of these members are defined in the Dos module;
  161.     id_NumSoftErrors, id_UnitNumber,....  See Dos.py.
  162.  
  163. DS2time(ds)
  164.     Convert DateStamp tuple to time() value (see time module)
  165.  
  166. time2DS
  167.     Convert time() value (see time module) to DateStamp tuple
  168.  
  169.  
  170.  
  171.  
  172.  
  173. ***************************************************************************
  174.  
  175.                                 MODULE: Dos
  176.  
  177.                                FILE: Dos.py
  178.  
  179. ***************************************************************************
  180.  
  181. This module is the interface to the Amiga's dos.library.
  182.  
  183. IMPORTANT:  this module uses the builtin Doslib module.  Don't use it
  184. yourself directly, always use the `Dos' module.
  185.  
  186. NOTE:
  187.  The whole lot of Dos LVO's that are not covered are considered:
  188.     - not useful;
  189.  or - unsafe (with regards to memory/lists/nodes/structs etc);
  190.  or - very difficult to use from Python.
  191.  Check the os and (amiga)path modules for things like file I/O,
  192.  path operations and other stuff.
  193.  
  194.  
  195. This module defines the following exception:
  196.  
  197.   error        - The exception that will be raised when an
  198.           error occurs related to dos.library. ('Doslib.error')
  199.           This is the same exception as the one from
  200.           the builtin Doslib module.
  201.  
  202.  
  203. +--------------------------------------+
  204. |                                      |
  205. |          DEFINED FUNCTIONS           |
  206. |                                      |
  207. +--------------------------------------+
  208.  
  209. As  this  module  imports everything from the Doslib module, see above what
  210. functions  are  provided.  Use the functions through this module, don't use
  211. the Doslib module directly.
  212.  
  213. There are some other functions implemented here as well:
  214.  
  215. touch(file [,time])        *** NEW ***
  216.     Changes the file's datestamp to the given time. Time is a Unix time value,
  217.     see the time module for more details (time.time). If omitted, the current
  218.     time is taken. If the specified file does not yet exist, it is created as
  219.     a zero-size file.
  220.  
  221. AddBuffers(drive, buffers)    *** NEW ***
  222.     A simple wrapper for c:addbuffers.
  223.  
  224. AssignAdd(name, target)        *** NEW ***
  225.     A simple wrapper for c:assign ADD.
  226.  
  227. AssignRemove(name)        *** NEW ***
  228.     A simple wrapper for c:assign REMOVE.
  229.  
  230.  
  231.  
  232. +--------------------------------------------+
  233. |                                            |
  234. |  DEFINED CONSTANTS (taken from dos/dos.h)  |
  235. |                                            |
  236. +--------------------------------------------+
  237.  
  238. - The break flags, SIGBREAKF_CTRL_C to SIGBREAKF_CTRL_F.
  239. - AmigaDOS file protection bits, including the `group' and `other' bits.
  240. - Flags and Format definitions for DateToStr and StrToDate.
  241.  
  242.  
  243. +--------------------------------------+
  244. |                                      |
  245. |          ARGPARSER CLASS             |
  246. |                                      |
  247. +--------------------------------------+
  248.  
  249. This  module  defines  the  ArgParser  class,  which  is an argument string
  250. parser.   It  can  be  used to parse ReadArgs() argument strings (the usual
  251. Amiga  style  for  command  lines,  all  CLI commands use it).  It works as
  252. follows:
  253.  
  254. p = Dos.ArgParser(template)
  255.  
  256.     Create new parser for the specified template.
  257.     template = ReadArgs template, like 'FROM/A/M,TO/A,QUIET/S'. 
  258.     
  259.     When parsing an argument string (see below) the type of the returned
  260.     Python value depends on the type of the argument in the template,
  261.     f.i. /N arguments will return an integer value.
  262.     `Multi'-options will ofcourse return a list.
  263.  
  264.     NOTE: /T (Switch Toggle) options are not supported.
  265.           (SystemError will be raised when you try to use /T)
  266.  
  267.     NOTE: ValueError will be raised when the template is considered
  268.           invalid.
  269.  
  270.  
  271. ** ArgParser objects have the following attributes:
  272.  
  273. defaults    - dictionary which contains the default values for each
  274.           template option which is not required (i.e. which is not
  275.           specified with /A switch). YOU MAY MODIFY THIS to change
  276.           the default options!!!
  277. template    - the template string. DO NOT MODIFY THIS! (use the `new'
  278.           member function to change the template)
  279. types        - internal type tuple. DO NOT MODIFY THIS! The structure is
  280.           as follows: ( (<template option>, <option type>), ... )
  281.           For instance when the template is 'FROM/A/M,TO/A,QUIET/S'
  282.           types will be (('FROM', ??), ('TO', ??), ('QUIET', ??)).
  283.           THE TYPE ENCODING IS PRIVATE, DO NOT TRY TO USE IT.
  284.  
  285.  
  286. ** ArgParser objects have the following member functions:
  287.  
  288. new(template)
  289.     modify the parser to use the new template
  290.  
  291. reset()
  292.     re-initialise the parser; reset defaults dictionary
  293.  
  294. parse(args)
  295.     The important one: parse the argument string args according to the
  296.     template of this ArgParser. Returns a dictionary containing the actual
  297.     arguments. The defaults dictionary is used to substitute default values
  298.     for unspecified arguments. Example:
  299.  
  300.     >>> p=Dos.ArgParser('FROM/A/M,TO/A,QUIET/S')
  301.     >>> p.defaults
  302.     {'QUIET': 0}
  303.     >>> p.types
  304.     (('FROM', 'A'), ('TO', 'X'), ('QUIET', 'S'))
  305.     >>> p.template
  306.     'FROM/A/M,TO/A,QUIET/S'
  307.     >>> p.parse('C:')
  308.     Doslib.error: You've forgotten an argument
  309.     >>> p.parse('C: ram:')
  310.     {'FROM': ['C:'], 'TO': 'ram:', 'QUIET': 0}
  311.     >>> r=p.parse('c:dir c:list c:copy TO RAM: quiet')
  312.     >>> print r
  313.     {'FROM': ['c:dir', 'c:list', 'c:copy'], 'TO': 'RAM:', 'QUIET': -1}
  314.     >>> for (o,t) in p.types: print 'Arg for',o,'is',r[o]
  315.     Arg for FROM is ['c:dir', 'c:list', 'c:copy']
  316.     Arg for TO is RAM:
  317.     Arg for QUIET is -1
  318.  
  319. Other member functions ARE PRIVATE.
  320.  
  321.   
  322.